<?php
/**
 * implements variable : {{ var }}, {{ container.var }}
 * Django's templating engine (partial) PHP implementation
 * @link http://djangoproject.com Django
 *
 * this file is from a webappkit package (kit)
 * @link http://webappkit.net
 * @package djtpl
 * @author J.Ducastel <nospam0@ducastel.name>
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 */
class djtplVarNode extends djtplNode {

    /**
    * builds from token
    * @param djtplToken $selfToken
    * @access public
    * @return bool
    */
    function buildFromTokens($selfToken/*, &$nextTokens*/) {
        // $this->token=&$selfToken;
        $this->path=$selfToken->getVarName();
        //echo wakdebug::vardump($selfToken);
        $this->filters=$selfToken->getVarFilters();
        return true;
    }/**/

    /**
    * Redners as string
    * @param &$context
    * @access public
    * @return string
    */
    function render(&$context) {
        // getting value
        $value=djtplParser::evalExpression($context,$this->path);
        //echo $value;
        if ($value===null) {
            //trigger_error("no value for {$this->path}");
            return '';
        }
        // applying filters
        foreach ($this->filters as $filter)
            $value=djtplParser::applyFilter($value,$filter);
        // returning formatted value
        if (is_object($value) and !method_exists($value,'__tostring'))
            return 'object '.get_class($value);
        else if (is_object($value))
            return $value->__tostring();
        return strval($value);
        //return '<!-- var: '.$this->token->varname.' -->';
    }/**/
}
